package com.ljx.controller;

import com.ljx.model.entity.Student;
import com.ljx.service.StudentServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Company: 上海数惠系统技术有限公司
 * Department: 数据中心：研发二部
 * Date: 2021/04/11 11:52
 *
 * @Author: Ljxpa
 * Email: lujx@dist.com.cn
 * Desc:
 */
@Api(tags = "学生控制器")
@RestController("/rest/student")
public class StudentController {

	@Autowired
	private StudentServiceImpl studentService;

	@ApiOperation("根据id查询学生信息")
	@GetMapping("/find/{id}")
	public ResponseEntity<Student> getOne(@PathVariable Integer id) {
		Student one = studentService.findOne(id);
		return ResponseEntity.ok(one);
	}

	@ApiOperation("查询所有学生信息")
	@GetMapping("/find/all")
	public ResponseEntity<List<Student>> getAll() {
		List<Student> all = studentService.getAll();
		return ResponseEntity.ok(all);
	}

	@ApiOperation("保存一个学生信息")
	@PostMapping("/save/one")
	public ResponseEntity<Student> saveOne(@RequestBody Student student) {
		Student one = studentService.saveOne(student);
		return ResponseEntity.ok(one);
	}

	@ApiOperation("查询id大于某个数的所有学生信息")
	@PostMapping("/find/many/greater/{id}")
	public ResponseEntity<List<Student>> findByIdGreaterThan(@PathVariable Integer id) {
		List<Student> students = studentService.findManyWithCondition(id);
		return ResponseEntity.ok(students);
	}

	@ApiOperation("查询id在某个范围内的所有学生信息")
	@PostMapping("/find/many/greater/{start}/{end}")
	public ResponseEntity<List<Student>> findByIdGreaterThan(@PathVariable Integer start, @PathVariable Integer end) {
		List<Student> students = studentService.findManyBetween(start, end);
		return ResponseEntity.ok(students);
	}
}
